package com.ai.controller.made;


import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.function.FunctionVO;
import com.ai.entity.made.camera.CameraBO;
import com.ai.entity.made.camera.CameraIdBO;
import com.ai.entity.made.page.CameraPage;
import com.ai.service.made.CameraFunctionsService;
import com.ai.service.made.CameraService;
import com.ai.service.made.ICamerasService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chen
 * @since 2023-03-28 11:12:30
 */
@Slf4j
@RestController
@RequestMapping("/camera")
public class CamerasController {

    @Resource
    ICamerasService camerasService;

    @Resource
    CameraService cameraService;

    @Resource
    CameraFunctionsService cameraFunctionsService;

    /**
     * 分页查询，列表查询
     *
     * @param page
     * @return
     */
    @ApiOperation("分页查询")
    @PostMapping("list")
    @PreAuthorize("hasAuthority('CAMERA_MANAGE')")
    @EnterPathParamLog
    public CommonResponse selectByPage(@RequestBody CameraPage page) {
        CommonResponse resultData = cameraService.selectByPage(page);
        return resultData;
    }


    /**
     * 通过ID查询
     *
     * @param cameraBO
     * @return
     */
    @ApiOperation("通过ID查询")
    @PostMapping("oneById")
    @EnterPathParamLog
    public CommonResponse oneById(@RequestBody CameraBO cameraBO) {
        CommonResponse resultData = cameraService.oneById(cameraBO);
        return resultData;
    }


    /**
     * 修改信息
     *
     * @param cameraBO
     * @return
     */
    @ApiOperation("修改信息")
    @PostMapping("modifyInfo")
    @EnterPathParamLog
    @PreAuthorize("hasAuthority('CAMERA_MANAGE')")
    public CommonResponse modifyInfo(@RequestBody CameraBO cameraBO) {
        CommonResponse resultData = cameraService.modifyInfo(cameraBO);

        return resultData;
    }


    /**
     * 添加
     *
     * @param cameraBO
     * @return
     */
    @ApiOperation("添加")
    @PostMapping("add")
    @EnterPathParamLog
    @PreAuthorize("hasAuthority('CAMERA_MANAGE')")
    public CommonResponse add(@RequestBody @Valid CameraBO cameraBO) {
        CommonResponse resultData = cameraService.insert(cameraBO);
        return resultData;
    }

    /**
     * 删除
     *
     * @param cameraBO
     * @return
     */
    @ApiOperation("删除")
    @PostMapping("delete")
    @EnterPathParamLog
    @PreAuthorize("hasAuthority('CAMERA_MANAGE')")
    public CommonResponse delete(@RequestBody CameraBO cameraBO) {
        CommonResponse resultData = cameraService.delete(cameraBO);
        return resultData;
    }



    @ApiOperation("查询开启摄像头列表")
    @PostMapping("listByOpen")
    @EnterPathParamLog
    public CommonResponse selectByOpen(@RequestBody CameraBO cameraBO) {
        CommonResponse resultData = cameraService.selectByOpen(cameraBO);
        return resultData;
    }


    /**
     * 批量关闭摄像头
     *
     * @param cameraIdBO
     */
    @ApiOperation("批量删除摄像头")
    @PostMapping("bulkDelete")
    @EnterPathParamLog
    @PreAuthorize("hasAuthority('CAMERA_MANAGE')")

    public CommonResponse bulkDelete(@RequestBody CameraIdBO cameraIdBO) {
        CommonResponse resultData = cameraService.bulkDelete(cameraIdBO);
        return resultData;
    }

//    @ApiOperation("查询人员流动摄像头列表")
//    @PostMapping("listByPersonFlow")
//    public CommonResponse listByPersonFlow(@RequestBody TCameraPage page) {
//        CommonResponse resultData = cameraService.listByPersonFlow(page);
//        return resultData;
//    }


    /**
     * 根据功能号查询摄像头列表
     *
     * @param function
     * @return
     */
    @ApiOperation("根据功能号查询摄像头列表")
    @PostMapping("selectByFunctionType")
    @EnterPathParamLog

    public CommonResponse selectByFunctionType(@RequestBody FunctionVO function) {
        CommonResponse resultData = cameraService.selectByFunctionType(function.getType());
        return resultData;
    }
//    @PostMapping(value = "/exportXls")
//    @EnterPathParamLog
//    public ModelAndView exportXls(@RequestBody TCameraPage page, HttpServletRequest request) {
//        // Step.1 组装查询条件
//        IPage cameraPage = camerasService.selectByPage(page);
//        //Step.2 AutoPoi 导出Excel
//        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
//        List<Cameras> pageList = cameraPage.getRecords();
//        //导出文件名称
//        mv.addObject(NormalExcelConstants.FILE_NAME, "摄像头列表");
//        mv.addObject(NormalExcelConstants.CLASS, Cameras.class);
//        ExportParams exportParams = new ExportParams("摄像头列表数据", "导出信息");
//        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
//        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
//        return mv;
//    }
}